package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.shippings.Shipping;
import com.blog.service.ShippingBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ShippingBaseController
 * @Destription Shipping基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/shipping")
public class ShippingBaseController {
    @Autowired
    ShippingBaseService shippingBaseService;
    @GetMapping("/selectAllShipping")
    public CommonRespDto selectAllShipping(){
        return CommonRespDto.success(shippingBaseService.selectAllShipping());
    }
    @GetMapping("/base/selectShippingById/{rid}")
    public CommonRespDto selectShippingById(@PathVariable Integer rid){
        return CommonRespDto.success(shippingBaseService.selectShippingById(rid.longValue()));
    }

    @PostMapping("/base/insertShipping")
    public RespBean insertShipping(@RequestBody Shipping shipping){
        if(shippingBaseService.insertShipping(shipping) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteShipping/{rid}")
    public RespBean deleteShippingById(@PathVariable Integer rid){
        if(shippingBaseService.deleteShippingById(rid.longValue()) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateShipping")
    public RespBean updateShipping(@RequestBody Shipping shipping){

        if(shippingBaseService.updateShipping(shipping) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
